package Chess.Pieces;

import java.awt.Color;
import Chess.*;

/**
 *	A class representing a Rook in Chess.
 *
 *	@author		Jeff Chan, James Kuo
 */
public class Rook extends Piece {

	public Rook(Color color) {
		super(color);
	}
	
	public boolean canAttack(Board board, Square currentSquare, Square occupiedSquare) {
		return (validSetupForAttack(board, currentSquare, occupiedSquare) &&
				board.clearPathBetween(currentSquare, occupiedSquare) &&
				differentSquareInSameRankOrFile(currentSquare, occupiedSquare));
	}

	public boolean canMove(Board board, Square currentSquare, Square emptySquare) {
		return (validSetupForMove(board, currentSquare, emptySquare) &&
				board.clearPathBetween(currentSquare, emptySquare) &&
				differentSquareInSameRankOrFile(currentSquare, emptySquare));
	}
	
	private boolean differentSquareInSameRankOrFile(Square square1, Square square2) {
		return !square1.equals(square2) && (square1.isInSameRank(square2) || square1.isInSameFile(square2));
	}

	@Override
	public PieceType getPieceType() {
		return PieceType.ROOK;
	}
}
